package Work4.Slay_the_Maze.Events;

import java.util.Scanner;
import java.util.Random;
import Work4.Slay_the_Maze.Cards.*;
import Work4.Slay_the_Maze.Player.Player;
import Work4.Slay_the_Maze.Potions.*;
import Work4.Slay_the_Maze.Relics.*;

public class TreasureEvent extends Events {
	public TreasureEvent() {
		super("宝箱！","看看里面有什么");
	}
	public void Takeit(Player player) {
		Scanner sc=new Scanner(System.in);
		Random rd=new Random();
		int num=rd.nextInt(100)+1;
		boolean isdone=false;
		CardsPool cardspool=new CardsPool();
		PotionsPool potionspool=new PotionsPool();
		Relicspool relicspool=new Relicspool();
		Relics relic=relicspool.RandomgetRelic();
		Potions potion=potionspool.RandomgetPotion();
		Cards card=cardspool.RandomgetCard();
		do {
			if(num>=1&&num<=60) {
				System.out.println("宝箱里有一件遗物");
				System.out.printf("遗物:");
				relic.PrintInfo();
				System.out.println("1.获得  2.离开");
				int choice;
				do {
					while (!sc.hasNextInt()) {
					    System.out.println("输入无效，请输入一个整数:");
					    sc.next(); // 清除错误输入，避免死循环
					}
					choice=sc.nextInt();
					if(choice!=1&&choice!=2) {
						System.out.println("输入无效:");
					}
				}while(choice!=1&&choice!=2);
				if(choice==1) {
					player.addrelics(player, relic);
					isdone=true;
				}else if(choice==2) {
					isdone=true;
				}
			}else if(num>=60&&num<=80) {
				System.out.println("宝箱里有一件遗物和一瓶药水");
				System.out.printf("遗物:");
				relic.PrintInfo();
				potion.PrintInfo();
				System.out.println("1.获得  2.离开");
				int choice;
				do {
					while (!sc.hasNextInt()) {
					    System.out.println("输入无效，请输入一个整数:");
					    sc.next(); // 清除错误输入，避免死循环
					}
					choice=sc.nextInt();
					if(choice!=1&&choice!=2) {
						System.out.println("输入无效:");
					}
				}while(choice!=1&&choice!=2);
				if(choice==1) {
					player.addrelics(player, relic);
					player.addpotions(potion);
					isdone=true;
				}else if(choice==2) {
					isdone=true;
				}
			}else if(num>=80&&num<=95) {
				System.out.println("宝箱里有一件遗物和一张卡牌");
				System.out.printf("遗物:");
				relic.PrintInfo();
				card.PrintInfo();
				System.out.println("1.获得  2.离开");
				int choice;
				do {
					while (!sc.hasNextInt()) {
					    System.out.println("输入无效，请输入一个整数:");
					    sc.next(); // 清除错误输入，避免死循环
					}
					choice=sc.nextInt();
					if(choice!=1&&choice!=2) {
						System.out.println("输入无效:");
					}
				}while(choice!=1&&choice!=2);
				if(choice==1) {
					player.addrelics(player, relic);
					player.addhandcard(card);
					isdone=true;
				}else if(choice==2) {
					isdone=true;
				}
			}else {
				System.out.println("宝箱里有一件遗物、一瓶药水和一张卡牌");
				System.out.printf("遗物:");
				relic.PrintInfo();
				potion.PrintInfo();
				card.PrintInfo();
				System.out.println("1.获得  2.离开");
				int choice;
				do {
					while (!sc.hasNextInt()) {
					    System.out.println("输入无效，请输入一个整数:");
					    sc.next(); // 清除错误输入，避免死循环
					}
					choice=sc.nextInt();
					if(choice!=1&&choice!=2) {
						System.out.println("输入无效:");
					}
				}while(choice!=1&&choice!=2);
				if(choice==1) {
					player.addrelics(player, relic);
					player.addpotions(potion);
					player.addhandcard(card);
					isdone=true;
				}else if(choice==2) {
					isdone=true;
				}
			}
		}while(!isdone);
	}
	public void doit(Player player) {
		Takeit(player);
	}
}
